package com.example.listener;

import com.example.config.SpringContextHolder;
import com.example.util.CustomConstant;
import com.example.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

@Slf4j
public class StartListener implements ApplicationListener<ContextRefreshedEvent> {
    @Bean
    public BCryptPasswordEncoder getPasswordEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        RedisUtil redisUtil = SpringContextHolder.getBean(RedisUtil.class);
        // 重置在线人数
        redisUtil.set(CustomConstant.REDIS_ONLINE_COUNT, 0);
        log.info("程序启动");
    }
}